<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<?php
    //连接数据库
	$conn;
	include '../public/conn.php';	

	//表单数据的获取
	$strName = $_POST["userName"];
	$strPwd = $_POST["userPwd"];
	$strType = $_POST["userType"];
	
	//插入数据
	if($strType=='1'){
		$result = mysql_query("SELECT * FROM student WHERE sna='$strName'");
		$num=mysql_num_rows($result);
		
		if($num==0)
		mysql_query("INSERT INTO student (sna,spw,type) VALUES ('$strName','$strPwd','$strType')");

		else{
			echo("<script>");
			echo("alert('该用户名已被注册!');");
			echo("window.location='sign.html';");
			echo("</script>");
		}
	}
	else if ($strType=='0'){
		$result = mysql_query("SELECT * FROM teacher WHERE tna='$strName'");
		$num=mysql_num_rows($result);
		
		if($num==0)
			mysql_query("INSERT INTO teacher (tna,tpw,type) VALUES ('$strName','$strPwd','$strType')");

		else{
			echo("<script>");
			echo("alert('该用户名已被注册!');");
			echo("window.location='sign.html';");
			echo("</script>");
		}
	}
	/* if(!mysql_query($sql)){
		die("error:".mysql_error());	
	} */
	echo("<script>");
	echo("alert('注册成功，请登陆!');");
	echo("window.location='sign.html#r';");
	echo("</script>");
	
	//关闭连接
	mysql_close();
?>